script_enemy_main{

let effect1=0;
let object1=[];
let cannonscale=0;
let cannonangle1=90;
let cannonangle2=90;

let cosx=0;

let character="Shinichi";
let cutin=character;
let dispelled=0;
let spellcards=2;
let spellcardnumber=3;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshot1=("script\SoundEffects\shotm4.wav");
let SEshot2=("script\SoundEffects\shotb2.wav");
let SEcannon=("script\SoundEffects\mechanic1normal.wav");

let GReffect1=("\script\Images\OtherEffects\Cannon.png");
let BG1=("\script\Images\BackgroundLayers\shinichi1.png");
let GRboss=("\script\Images\CharacterSprites\Shinichi.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsShinichi1.txt");

	LoadGraphic("\script\Images\CharacterSprites\Shinichi.png");
	LoadGraphic("\script\Images\BackgroundLayers\shinichi1.png");
	LoadGraphic("\script\Images\OtherEffects\Cannon.png");

	LoadSE("script\SoundEffects\shotm4.wav");
	LoadSE("script\SoundEffects\shotb2.wav");
	LoadSE("script\SoundEffects\mechanic1normal.wav");

	SetScore(500000);
	SetLife(200);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+120,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(150,150,150,150);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=4; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }
SpellcardName("Tactics [Suppressive Fire] ("~difficulty~")",spellcardnumber);

HealthBar();
Portrait(cutin,1);

if((time+60)%120==0 && time>=120){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+80,miny+130),1);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+80,miny+130),1);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+80,miny+130),1);
	}
}


if(time==60){
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Suppressive Fire - Familiar.txt"),GetX,GetY,0,0,[1,100,10]);
	CreateEnemyFromFile((GetCurrentScriptDirectory~"Shinichi - Suppressive Fire - Familiar.txt"),GetX,GetY,0,0,[2,100,10]);
}

if(time%120==0 && time>=60){
let bullet1=0;
let bullet2=1;
SetShotDirectionType(PLAYER);
CreateShotA(bullet1,GetX-10,GetY-30,30);
SetShotDataA(bullet1,0,1,0,0,0.03,4,25);
	loop(3){
	CreateShotA(bullet2,0,0,20);
	SetShotDataA(bullet2,0,0.3,rand(-30,30),0,rand(0.01,0.015),4,38);
	AddShot(60,bullet1,bullet2,0);
	}
	loop(3){
	CreateShotA(bullet2,0,0,20);
	SetShotDataA(bullet2,0,0.3,rand(-30,30),0,rand(0.01,0.015),4,37);
	AddShot(130,bullet1,bullet2,0);
	}
FireShot(bullet1);

SetShotDirectionType(ABSOLUTE);
PlaySE(SEshot2);
usespell=30;
}



if(time==40){
	loop(2){
	effect1=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(effect1,GetX,GetY-10); ObjEffect_SetScale(effect1,1,1);
	Obj_SetAngle(effect1,0); ObjEffect_SetAngle(effect1,0,0,0);
	ObjEffect_SetLayer(effect1,1); ObjEffect_SetTexture(effect1,GReffect1); ObjEffect_SetRenderState(effect1,ALPHA);
	ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
	ObjEffect_SetVertexXY(effect1,0,-120,-15); ObjEffect_SetVertexUV(effect1,0,0,0);
	ObjEffect_SetVertexXY(effect1,1,120,-15); ObjEffect_SetVertexUV(effect1,1,240,0);
	ObjEffect_SetVertexXY(effect1,2,-120,15); ObjEffect_SetVertexUV(effect1,2,0,30);
	ObjEffect_SetVertexXY(effect1,3,120,15); ObjEffect_SetVertexUV(effect1,3,240,30);
	ObjEffect_SetVertexColor(effect1,0,255,255,255,255); ObjEffect_SetVertexColor(effect1,1,255,255,255,255);
	ObjEffect_SetVertexColor(effect1,2,255,255,255,255); ObjEffect_SetVertexColor(effect1,3,255,255,255,255);
	object1=object1~[effect1];
	}
PlaySE(SEcannon);
}

if(time>=40){
if(cannonangle1>-30){ cannonangle1-=2; }
if(cannonangle2<210){ cannonangle2+=2; }
	Obj_SetPosition(object1[0],GetX,GetY-10);
	Obj_SetPosition(object1[1],GetX,GetY-10);

	Obj_SetAngle(object1[0],cannonangle1); ObjEffect_SetAngle(object1[0],0,0,cannonangle1);
	Obj_SetAngle(object1[1],cannonangle2); ObjEffect_SetAngle(object1[1],0,0,cannonangle2);

	ObjEffect_SetScale(object1[0],cannonscale,1); ObjEffect_SetScale(object1[1],cannonscale,1);
	if(cannonscale<1){ cannonscale+=0.02; }
}



time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

SetCommonData("Boss2X",GetX); SetCommonData("Boss2Y",GetY); 
}

@BackGround{
	if(bgfade<200){bgfade+=5;}

	SetGraphicRect(0+(time*2),0+(time*2),900+(time*2),600+(time*2));
	SetGraphicScale(1,1);
	SetTexture(BG1);
	SetAlpha(bgfade);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	SetGraphicAngle(0,0,0);
	DrawGraphic(cx,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
//	SetCommonData("Conversation",1);
	SetCommonData("ItemSpawn",1);
	NewPointData(spellcardnumber,GetCommonData("Difficulty"));
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}